<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
  event_list ||= nil
  title ||= t('titles.events', "Events")
  display_count ||= 3
  display_count += 1 if event_list.length == display_count + 1
  period ||= nil
  show_context ||= false
  show_more ||= true
  upcoming ||= false
  is_recent_feedback ||= false
  partial = is_recent_feedback ? 'courses/recent_feedback' : 'courses/recent_event'
  contexts_to_link_to ||= nil
%>
<div class="events_list <%= is_recent_feedback ? 'recent_feedback' : 'coming_up' %>">
  <h2><% unless is_recent_feedback %><a class='event-list-view-calendar icon-calendar-day standalone-icon' href='<%= calendar_url_for(contexts_to_link_to) %>'><%= t 'links.view_calendar', "View Calendar" %></a><% end %> <%= title %></h2>
  <ul class="right-side-list events">
  <% if !event_list || event_list.empty? %>
    <li>
      <small>
        <% if period == :one_week %>
          {{#t}}Nothing for the next week{{/t}}
        <% elsif period == :two_weeks && !is_recent_feedback %>
          {{#t}}Nothing for the next two weeks{{/t}}
        <% else %>
          {{#t}}Nothing for now{{/t}}
        <% end %>
      </small>
    </li>
  <% else %>
    <% (event_list || []).each_with_index do |e, i| %>
      <%= render :partial => partial, :object => e, :locals => {:show_context => show_context, :is_hidden => i >= display_count, :upcoming => upcoming } %>
    <% end %>
    <% if event_list.length > display_count && show_more %>
    <li>
      <a href="#" class="more_link">
      <% if event_list.length >= 20 %>
        <% if upcoming %>
          <% if period == :one_week %>
            <%= t('at_least_more_events_one_week_future', 'at least %{count_of_events} more in the next week', :count_of_events => (event_list.length - display_count)) %>
          <% elsif period == :two_weeks %>
            <%= t('at_least_more_events_two_weeks_future', 'at least %{count_of_events} more in the next two weeks', :count_of_events => (event_list.length - display_count)) %>
          <% else %>
            <%= t('at_least_more_events', 'at least %{count_of_events} more', :count_of_events => (event_list.length - display_count)) %>
          <% end %>
        <% else %>
          <% if period == :one_week %>
            <%= t('at_least_more_events_one_week', 'at least %{count_of_events} more in the past week', :count_of_events => (event_list.length - display_count)) %>
          <% elsif period == :two_weeks %>
            <%= t('at_least_more_events_two_weeks', 'at least %{count_of_events} more in the past two weeks', :count_of_events => (event_list.length - display_count)) %>
          <% else %>
            <%= t('at_least_more_events', 'at least %{count_of_events} more', :count_of_events => (event_list.length - display_count)) %>
          <% end %>
        <% end %>
      <% else %>
        <% if upcoming %>
          <% if period == :one_week %>
            <%= t('more_events_one_week_future', '%{count_of_events} more in the next week', :count_of_events => (event_list.length - display_count)) %>
          <% elsif period == :two_weeks %>
            <%= t('more_events_two_weeks_future', '%{count_of_events} more in the next two weeks', :count_of_events => (event_list.length - display_count)) %>
          <% else %>
            <%= t('more_events', '%{count_of_events} more', :count_of_events => (event_list.length - display_count)) %>
          <% end %>
        <% else %>
          <% if period == :one_week %>
            <%= t('more_events_one_week', '%{count_of_events} more in the past week', :count_of_events => (event_list.length - display_count)) %>
          <% elsif period == :two_weeks %>
            <%= t('more_events_two_weeks', '%{count_of_events} more in the past two weeks', :count_of_events => (event_list.length - display_count)) %>
          <% else %>
            <%= t('more_events', '%{count_of_events} more', :count_of_events => (event_list.length - display_count)) %>
          <% end %>
        <% end %>
      <% end %>
        &hellip;</a>
    </li>
    <% end %>
  <% end %>
  </ul>
</div>
